package com.hjq.mallseckill.controller;

import com.hjq.common.utils.R;
import com.hjq.mallseckill.entity.to.SeckillSkuRedisTO;
import com.hjq.mallseckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @auther HJQ
 */
@Controller
public class SecKillController {
    @Autowired
    SeckillService seckillService;
    @ResponseBody
    @RequestMapping("/getCurrentSecSkus")
    public R getCurrentSecSkus(){
        List<SeckillSkuRedisTO> vos=seckillService.getCurrentSecSkus();
        return R.ok().put("data",vos);
    }
    @ResponseBody
    @RequestMapping("/sku/seckill/{skuId}")
    public R getSkuSecInfo(@PathVariable("skuId") Long skuId){
        SeckillSkuRedisTO vo=seckillService.getSkuSecInfo(skuId);
        return R.ok().put("data",vo);
    }
    @RequestMapping("/killerQween.html")
    public String kill(@RequestParam("killId") String killId,
                       @RequestParam("number") Integer number,
                       @RequestParam("key") String code, Model model){
        String orderSn=seckillService.kill(killId,number,code);
        model.addAttribute("orderSn",orderSn);
        return "success";
    }

}
